package com.dnjn.happiness.biz.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.CommunicateAssign;
import com.dnjn.happiness.biz.service.ICommunicateAssignService;
import com.dnjn.happiness.common.core.utils.poi.ExcelUtil;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 沟通指派记录 前端控制器
 * </p>
 *
 * @author Amber
 * @since 2023-10-04
 */
@Tag(name = "biz CommunicateAssign 沟通指派记录", description = "沟通指派记录")
@RestController
@RequestMapping("/communicate-assign")
public class CommunicateAssignController extends BaseController {

    @Autowired
    protected ICommunicateAssignService baseService;

    @GetMapping("/get/{id}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable Long id) {
        return success(baseService.getById(id));
    }

    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody CommunicateAssign domain) {
        domain.setCreateBy(SecurityUtils.getUsername());
        return toAjax(baseService.save(domain));
    }

    @RequiresPermissions("/biz/communicate-assign:edit")
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody CommunicateAssign domain) {
        return toAjax(baseService.updateById(domain));
    }

    @RequiresPermissions("/biz/communicate-assign:query")
    @DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds) {
        baseService.removeBatchByIds(Arrays.asList(pkIds));
        return success();
    }

    @RequiresPermissions("/biz/communicate-assign:query")
    @PostMapping("/page")
    public AjaxResult page(@RequestBody CommunicateAssign domain, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        Page page = Page.of(current, size);
        Page<CommunicateAssign> list = baseService.page(page, Wrappers.query(domain));
        return success(list);
    }

    @RequiresPermissions("/biz/communicate-assign:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunicateAssign domain) {
        List<CommunicateAssign> list = baseService.list(Wrappers.query(domain));
        ExcelUtil<CommunicateAssign> util = new ExcelUtil<CommunicateAssign>(CommunicateAssign.class);
        util.exportExcel(response, list, "参数数据");
    }


}